//createRouter   ：创建路由实例对象
//createWebHistory  ：创建History模式路由
import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList from '@/views/CartList/index.vue'
import Checkout from '@/views/Checkout/index.vue'
import Pay from '@/views/Pay/index.vue'
import PayBack from '@/views/Pay/PayBack.vue'
import SearchGoods from '@/views/Search/index.vue'
import Member from '@/views/Member/index.vue'
import UserInfo from '@/views/Member/components/UserInfo.vue'
import UserOrder from '@/views/Member/components/UserOrder.vue'
import SellerLogin from '@/views/Seller/Login/index.vue'
import SellerLayout from '@/views/Seller/Layout/index.vue'
import SellerGoodsMange from '@/views/Seller/goods/GoodsManage.vue'
import SellerOrderMange from '@/views/Seller/goods/OrderManage.vue'
import SellerInfoMange from '@/views/Seller/user/UserInfo.vue'
import SellerPasswordMange from '@/views/Seller/user/UserResetPassword.vue'
import AdminLogin from '@/views/Admin/Login/index.vue'
import AdminLayout from '@/views/Admin/Layout/index.vue'
import AdminUserInfo from '@/views/Admin/user/UserInfo.vue'
import AdminSellerInfo from '@/views/Admin/user/SellerInfo.vue'
import AdminGoodsMange from '@/views/Admin/goods/index.vue'
import AdminCommentMange from '@/views/Admin/goods/components/comment.vue'
import AdminCategory from '@/views/Admin/category/index.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  //配置path和component对应关系的位置
  //path：路径    component：组件
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        {
          //执行父路由，子路由path为空时，自动渲染(默认二级路由)
          path: '',
          component: Home
        },
        {
          path: 'category/:id',
          component: Category
        },
        {
          path: 'category/sub/:id',
          component: SubCategory
        },
        {
          path: 'detail/:id',
          component: Detail
        },
        {
          path: 'cartlist',
          component: CartList
        },
        {
          path: 'checkout',
          component: Checkout
        },
        {
          path: 'pay',
          component: Pay
        },
        {
          path: 'payback',
          component: PayBack
        },
        {
          path: 'search/:keyword',
          component: SearchGoods
        },
        {
          path: 'member',
          component: Member,
          children: [
            {
              path: 'user',
              component: UserInfo
            },
            {
              path: 'order',
              component: UserOrder
            }
          ]
        }
      ]
    },
    {
      path: '/Login',
      component: Login
    },
    {
      path: '/Seller/Login',
      component: SellerLogin
    },
    {
      path: '/seller',
      component: SellerLayout,
      redirect: '/seller/order',
      children: [
        {
          path: 'goods',
          component: SellerGoodsMange
        },
        {
          path: 'order',
          component: SellerOrderMange
        },
        {
          path: 'infoMange',
          component: SellerInfoMange
        },
        {
          path: 'passwordMange',
          component: SellerPasswordMange
        }
      ]
    },
    {
      path: '/admin/Login',
      component: AdminLogin
    },
    {
      path: '/admin',
      component: AdminLayout,
      redirect: '/admin/userInfo',
      children: [
        {
          path: 'userInfo',
          component: AdminUserInfo
        },
        {
          path: 'sellerInfo',
          component: AdminSellerInfo
        },
        {
          path: 'goods',
          component: AdminGoodsMange
        },
        {
          path: 'comment/:id',
          component: AdminCommentMange
        },
        {
          path: 'category',
          component: AdminCategory
        }
      ]
    }
  ],
  //路由滚动行为定制（切换页面后到顶端）
  scrollBehavior() {
    return {
      top: 0,
      behavior: 'smooth'
    }
  }
});

//导航守卫、路由首位、路由拦截
// router.beforeEach(
//   (to,from,next) => {
//     //验证token
//   }
//  )

export default router
